package com.wei.czz.common.exception;

import com.wei.czz.common.enums.ResultEnum;
import lombok.Getter;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2021-02-26 20:42:00
 * className CzzException 自定义运行时异常处理类
 * version: 1.0
 * description:
 * 		继承RuntimeException类
 */
@Getter
public class CzzException extends RuntimeException {
	private static final long serialVersionUID = 1L;

	/**
	 * 异常状态码
	 */
	private final Integer code;

	public CzzException() {
		this(ResultEnum.SERVICE_FAIL);
	}

	/**
	 * 异常消息存储于上级对象中
	 * @param msg 异常消息
	 */
	public CzzException(String msg) {
		this(ResultEnum.SERVICE_FAIL.getCode(), msg);
	}

	public CzzException(String msg, Throwable e) {
		this(ResultEnum.SERVICE_FAIL.getCode(), msg, e);
	}

	public CzzException(Integer code, String msg) {
		super(msg);
		this.code = code;
	}

	public CzzException(Integer code, String msg, Throwable e) {
		super(msg, e);
		this.code = code;
	}

	public CzzException(ResultEnum resultEnum) {
		this(resultEnum.getCode(), resultEnum.getMsg());
	}

	public CzzException(Throwable cause) {
		super(cause);
		this.code = ResultEnum.SERVICE_FAIL.getCode();
	}
}
